#
# mingw makefile generics
#

CC      = ${MINGWBASE}gcc
CXX     = ${MINGWBASE}g++
AR      = ${MINGWBASE}ar
OBJCOPY = ${MINGWBASE}objcopy
STRIP   = ${MINGWBASE}strip --strip-unneeded
WINDRES = ${MINGWBASE}windres
PEFIX   = ${pefix}

BINEXT  = .exe

DSOLDFLAGS = -shared
DSOPRE     =
DSOPOST    = .dll
DSORPATH   =
DSOSONAME  = -Wl,-soname,

# Use MSVCRT directly for stdio; it's faster
ARCH_CFLAGS   += -D__USE_MINGW_ANSI_STDIO=0
ARCH_CXXFLAGS += -D__USE_MINGW_ANSI_STDIO=0

# Fix MINGW's shared library fanaticism
ARCH_LDFLAGS += -static-libstdc++ -static-libgcc

# OpenGL must be linked to MZX
core_ldflags += -lopengl32

# Windows needs PNG to be statically linked (inc. zlib)
LIBPNG_LDFLAGS = `libpng-config --static --ldflags`

ifdef DEBUG
ARCH_LDFLAGS += -mconsole
endif

pefix := arch/mingw/pefix${BINEXT}

-include arch/mingw/pefix.d

arch/mingw/pefix.o: arch/mingw/pefix.c
	$(if ${V},,@echo "  CC      " $<)
	${HOST_CC} -MD ${CFLAGS} -c $< -o $@

${pefix}: arch/mingw/pefix.o
	$(if ${V},,@echo "  LINK    " ${pefix})
	${HOST_CC} arch/mingw/pefix.o -o ${pefix}

all: ${pefix}

clean:
	${RM} -f ${pefix} arch/mingw/pefix.o arch/mingw/pefix.d

#
# Windows builds must copy SDL.dll and create a directx.bat
#
build: ${build}
	${CP} ${shell sdl-config --prefix}/bin/SDL.dll ${build}
	${PEFIX} ${build}/SDL.dll
	${CP} arch/mingw/directx.bat ${build}
ifeq (${BUILD_UTILS},1)
	${CP} arch/mingw/checkres* ${build}/utils
endif
	@arch/manifest.sh ${build}

SUBARCH := ${shell echo ${SUBPLATFORM} | sed 's,windows-,,'}
include arch/zip.inc 
